
#ifndef __COROUTINE_IMP_H__
#define __COROUTINE_IMP_H__

#include "bd_list.h"

#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
	#include <SDKDDKVer.h>
	#include <Windows.h>
	#define coro_platform_ctx LPVOID
#else
	#include <ucontext.h>
	#include <stdlib.h>
	#include <string.h>
	#define coro_platform_ctx ucontext_t
#endif

enum coro_stat_t
{
	coro_stat_null,
	coro_stat_ready,
	coro_stat_run,
	coro_stat_wait,
	coro_stat_dead,
};

struct coroutine
{
	bd_node node;
	coro_platform_ctx ctx;
	size_t stk_size;
	void (*func)(void*);
	void* data;
	coro_stat_t status;
};

struct coro_schedule
{
	coroutine* coro_main;
	coroutine* coro_curr;
	bd_list coro_ready_list;
	bd_list coro_dead_list;
	bd_list coro_cache_list;
	size_t coro_stack_size;
	size_t max_coro_size;
};


#endif //__COROUTINE_IMP_H__

